package de.java.shortys.myhome.api.view;

import static de.java.shortys.myhome.viewconfigurator.configuration.ViewConfigurationConstants.SWINGMODULEVIEW_TREE_FOREGROUND;
import static java.awt.Font.BOLD;
import static java.awt.Font.PLAIN;

import java.awt.Color;
import java.awt.Component;
import java.awt.Font;

import javax.swing.JTree;
import javax.swing.tree.DefaultTreeCellRenderer;

import de.java.shortys.myhome.viewconfigurator.controller.ViewConfigurationManager;

public class SwingModuleViewTreeCellRenderer extends DefaultTreeCellRenderer {

	@Override
	@SuppressWarnings("all")
	public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded,
			boolean leaf, int row, boolean hasFocus) {
		super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
		Color transparent = ViewConfigurationManager.getTransparency();
		this.setBackgroundNonSelectionColor(transparent);
		this.setBackgroundSelectionColor(null);
		this.setBorderSelectionColor(null);
		this.setForeground(ViewConfigurationManager.getInstance().getColor(SWINGMODULEVIEW_TREE_FOREGROUND));

		if (sel) {
			this.setFont(new Font(getFont().getName(), BOLD, getFont().getSize()));
		} else {
			this.setFont(new Font(getFont().getName(), PLAIN, getFont().getSize()));
		}
		return this;

	}
}
